{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "6d0df1f6",
   "metadata": {},
   "source": [
    "# 上周回顾\n",
    "\n",
    "> 1.while循环：while True-->无限循环\n",
    "\n",
    ">> 1.指定次数，while True 可以实现for循环的指定次数，增加一个count计数器即可。\n",
    ">> 2.while True 一般与用户输入 一起使用，让用户可以重复输入，知道某些条件成立结束输入（购物车）\n",
    "\n",
    "> 2.购物车实践\n",
    "\n",
    "\n",
    "# 本周内容\n",
    "\n",
    "> 1.元组\n",
    "\n",
    "> 2.集合\n",
    "\n",
    "> 3.字典"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b652d015",
   "metadata": {},
   "source": [
    "# 1.元组（tuple）\n",
    "\n",
    "> 1.元组的基本内容（形态、定义）\n",
    "\n",
    "> 2.元组的性质\n",
    "\n",
    ">> 1.有序性(indexing,sliceing)\n",
    "\n",
    ">> 2.<font color=\"red\">**不可变性</font>,元组没有：增、删、改\n",
    "\n",
    "> 3.元组的一般方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "6e61836d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(210001, 210002, 210003) <class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "网二_学号 = (210001,210002,210003)\n",
    "print(网二_学号,type(网二_学号))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "87eacc5e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(200001, 200002, 200003) <class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "网三_学号 = 200001,200002,200003\n",
    "print(网三_学号,type(网三_学号))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "daeaf821",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "210001"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网二_学号[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "32aea770",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(210002, 210003)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网二_学号[1:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "b6f94836",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2022, tm_mon=10, tm_mday=25, tm_hour=15, tm_min=6, tm_sec=38, tm_wday=1, tm_yday=298, tm_isdst=0)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 元组的实际案例\n",
    "\n",
    "import time\n",
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "0214bf31",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "([1, 2, 3, 4], [3, 4, 5, 6]) <class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "tuple_test = ([1,2,3,4],[3,4,5,6])\n",
    "print(tuple_test,type(tuple_test))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "117a38a5",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 一般情况下，元组里面存放的是常量  常量（不可变），常量：数字，字符串\n",
    "#                     不存放变量 如：列表，字典"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2ea0555f",
   "metadata": {},
   "source": [
    "## 2.集合 （sets）\n",
    "\n",
    "> 1.集合的基本概念\n",
    "\n",
    ">> 1.性质：没有重复项；无序性\n",
    "\n",
    "> 2.集合的一般方法:intersection,\n",
    ">> 1.集合的运算：\n",
    ">> 2."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "197fb68f",
   "metadata": {},
   "outputs": [],
   "source": [
    "basket_list = \n",
    "basket_sets ="
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "94534778",
   "metadata": {},
   "outputs": [],
   "source": [
    "舞蹈社 = {1801,1802,1803,1809,1811,1812}\n",
    "电竞社 = {1808,1822,1809,1812,1806,1811}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "4345604c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1809, 1811, 1812}"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "舞蹈社 & 电竞社"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "9c57d7b7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1809, 1811, 1812}"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "舞蹈社.intersection(电竞社)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "84e601c7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1801, 1802, 1803, 1806, 1808, 1809, 1811, 1812, 1822}"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "舞蹈社 | 电竞社"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "acbba69e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(舞蹈社 | 电竞社)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "023b2885",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1801, 1802, 1803, 1806, 1808, 1809, 1811, 1812, 1822}"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "舞蹈社.union(电竞社)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5986822d",
   "metadata": {},
   "source": [
    "# 3.字典（dict）\n",
    "\n",
    "> 1.字典的基本概念：\n",
    "\n",
    ">> 1.字典性质\n",
    "\n",
    ">>> 1.无序性\n",
    ">>> 2.keys 是不可变的:就像列表、字符串等有序的数据结构 它的index不可变是一样的\n",
    ">>> 3.keys 是唯一的\n",
    "\n",
    ">> 2.字典的形态"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "d7357d94",
   "metadata": {},
   "outputs": [],
   "source": [
    "网新二班 = {\n",
    "    1800001:\"吴易凡\",\n",
    "    1800002:\"Jay\",\n",
    "    1800003:\"Frances\",\n",
    "    1800004:\"李一峰\"\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "dca273be",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1800001: '吴易凡', 1800002: 'Jay', 1800003: 'Frances', 1800004: '李一峰'} <class 'dict'>\n"
     ]
    }
   ],
   "source": [
    "print(网新二班,type(网新二班))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0c603a39",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 因为学号是唯一的，可以作为字典的key"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "d1f4034e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1800001: '吴易凡', 1800002: 'Jay', 1800003: 'Frances', 1800004: '李一峰'} <class 'dict'>\n"
     ]
    }
   ],
   "source": [
    "网新三班 = {\n",
    "    1800001:\"吴易凡\",\n",
    "    1800002:\"Jay\",\n",
    "    1800003:\"Frances\",\n",
    "    1800004:\"李一峰\"\n",
    "}\n",
    "print(网新三班,type(网新三班))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "5b9fc101",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'李一峰'"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 字典的取值: 通过keys 进行字典的取值， 不像列表和元组和字符串通过index取值\n",
    "\n",
    "网新三班[1800004]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5f5d0ccd",
   "metadata": {},
   "outputs": [],
   "source": [
    "网新二班 = {\n",
    "    1800001:[\"吴易凡\",\"广州\",\"男\",19,\"聊天记录\",\"朋友圈\"],\n",
    "    1800002:\"Jay\",\n",
    "    1800003:\"Frances\",\n",
    "    1800004:\"李一峰\"\n",
    "}"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
